package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 查询被推荐的用户
     *
     * @param userId
     * @return
     */
    public UserInfo queryUserInfoByUserId(Long userId) {
        //创建构造条件器，查询数据库
        QueryWrapper<UserInfo> query = new QueryWrapper<>();
        query.eq("user_id", userId);
        return this.userInfoMapper.selectOne(query);
    }

    /**
     * 查询个人用户资料
     *
     * @param queryWrapper
     * @return
     */

    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }


    /**
     * 根据用户传的id，查询具体信息
     *
     * @param userIds
     * @return
     */
    public List<UserInfo> queryUserInfoByUserIdList(List<?> userIds) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id", userIds);
        return this.queryUserInfoList(queryWrapper);
    }

    /**
     * 通过用户id来查找数据
     *
     * @param userInfo
     * @return
     */
    public Boolean queryUpdate(UserInfo userInfo) {
        //创建查询构造器
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id" ,userInfo.getUserId());
        //修改成功返回true
        return this.userInfoMapper.update(userInfo,queryWrapper) > 0;
    }

}
